    //
//  FacilityViewController.m
//  YJRenter
//
//  Created by 文彬 on 2018/7/12.
//  Copyright © 2018年 文彬. All rights reserved.
//

#import "FacilityViewController.h"
#import "ItemSelectTableViewCell.h"

@interface FacilityViewController ()<UITableViewDelegate,
    UITableViewDataSource>

@property (strong, nonatomic) UITableView *listTableView;
@property (strong, nonatomic) NSArray *listDatas;

@end

@implementation FacilityViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self initPageControl];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (void)initPageControl{
    
    [self.view addSubview:self.listTableView];
    [self.listTableView makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(@0);
        make.bottom.equalTo(@-50);
    }];
    
    [self addTableHeader];
    
    UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [closeBtn setBackgroundImage:[UIImage imageNamed:@"CheckSelected"] forState:UIControlStateNormal];
    [self.view addSubview:closeBtn];
    [closeBtn makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.equalTo(@30);
        make.centerX.equalTo(self.view.centerX);
        make.bottom.equalTo(@-5);
    }];
    [closeBtn buttonClick:^{
        [self dismissViewControllerAnimated:YES completion:nil];
    }];
}

- (void)addTableHeader{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 100)];
    view.backgroundColor = [UIColor whiteColor];
    
    UILabel *titleLabel = [[UILabel alloc]init];
    titleLabel.font = [UIFont systemFontOfSize:20];
    titleLabel.textColor = kTitleColor;
    titleLabel.text = @"设施服务";
    [view addSubview:titleLabel];
    [titleLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.height.equalTo(@35);
        make.centerY.equalTo(view.centerY);
        make.width.equalTo(@100);
    }];
    
    self.listTableView.tableHeaderView = view;
}

#pragma mark UITableView
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.listDatas.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 2;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.5;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row==0) {
        return 40;
    }
    if (indexPath.section==0) {
        return 300;
    }
    else if(indexPath.section==1){
        return 100;
    }
    return 200;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSDictionary *dict = self.listDatas[indexPath.section];
    
    if(indexPath.row==0){
        
        NSString *iden = @"iden";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:iden];
        if (cell==nil) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:iden];
            cell.textLabel.font = [UIFont systemFontOfSize:16];
            cell.textLabel.textColor = kTitleColor;
        }
        cell.textLabel.text = dict[@"title"];
        
        return cell;
    }
    
    
    ItemSelectTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ItemSelectTableViewCell" forIndexPath:indexPath];
     [cell setData:dict[@"data"] oneLineCount:4];
    
    return cell;
}

#pragma mark getter
- (UITableView*)listTableView{
    if (_listTableView==nil) {
        _listTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _listTableView.delegate = self;
        _listTableView.dataSource = self;
        _listTableView.sectionFooterHeight = 0;
        _listTableView.backgroundColor = [UIColor clearColor];
        _listTableView.separatorStyle = UITableViewCellSeparatorStyleNone;        [_listTableView registerNib:[UINib nibWithNibName:@"ItemSelectTableViewCell" bundle:nil] forCellReuseIdentifier:@"ItemSelectTableViewCell"];
    }
    
    return _listTableView;
}

- (NSArray*)listDatas{
    if (_listDatas==nil) {
        _listDatas = @[@{@"title":@"居家",
                         @"data":@[@{@"title":@"无线wifi",@"pic":@"header_default"},
                                   @{@"title":@"电视",@"pic":@"header_default"},
                                   @{@"title":@"淋浴",@"pic":@"header_default"},
                                   @{@"title":@"空调",@"pic":@"header_default"},
                                   @{@"title":@"冰箱",@"pic":@"header_default"},
                                   @{@"title":@"洗衣机",@"pic":@"header_default"},
                                   @{@"title":@"热水壶",@"pic":@"header_default"},
                                   @{@"title":@"吹风机",@"pic":@"header_default"},
                                   @{@"title":@"衣架",@"pic":@"header_default"},
                                   @{@"title":@"扫把",@"pic":@"header_default"}
                                   ]},
                       @{@"title":@"卫浴",
                         @"data":@[@{@"title":@"拖鞋",@"pic":@"header_default"},
                                   @{@"title":@"毛巾",@"pic":@"header_default"},
                                   @{@"title":@"牙刷",@"pic":@"header_default"},
                                   @{@"title":@"卫生纸",@"pic":@"header_default"}
                                   ]},
                       @{@"title":@"餐厨",
                         @"data":@[@{@"title":@"燃气灶",@"pic":@"header_default"},
                                   @{@"title":@"烹饪锅",@"pic":@"header_default"},
                                   @{@"title":@"电饭煲",@"pic":@"header_default"},
                                   @{@"title":@"餐具",@"pic":@"header_default"},
                                   @{@"title":@"洗涤用具",@"pic":@"header_default"}
                                   ]},
                       @{@"title":@"周边500米",
                         @"data":@[@{@"title":@"超市",@"pic":@"header_default"},
                                   @{@"title":@"餐厅",@"pic":@"header_default"},
                                   @{@"title":@"游乐园",@"pic":@"header_default"},
                                   @{@"title":@"药店",@"pic":@"header_default"},
                                   @{@"title":@"提款机",@"pic":@"header_default"}
                                   ]}
                       ];
    }
    return _listDatas;
}

@end
